#include "Endian.h"

#include <string.h>
#include <fan-llvm/core/Core.h>
#include "Type.h"
#include "UnsupportedErr.h"


Type* Endian_classType = NULL;
VTable* Endian_classVTable = NULL;


/**********************************************
 *
 * Methods and fields
 *
 **********************************************/


/* Endian big */
Endian* Endian_big(void)
{
  exceptionThrow(UnsupportedErr_newWithFormattedMsg("sys::Endian.big not implemented yet"));
}


/* Endian little */
Endian* Endian_little(void)
{
  exceptionThrow(UnsupportedErr_newWithFormattedMsg("sys::Endian.little not implemented yet"));
}


/* Endian[] vals */
List* Endian_vals(void)
{
  exceptionThrow(UnsupportedErr_newWithFormattedMsg("sys::Endian.vals not implemented yet"));
}


/* Endian? fromStr(Str name, Bool checked) */
Endian* Endian_fromStr_1(Str* name)
{
  exceptionThrow(UnsupportedErr_newWithFormattedMsg("sys::Endian.fromStr not implemented yet"));
}


/* Endian? fromStr(Str name, Bool checked) */
Endian* Endian_fromStr(Str* name, Bool checked)
{
  exceptionThrow(UnsupportedErr_newWithFormattedMsg("sys::Endian.fromStr not implemented yet"));
}


/**********************************************
 *
 * Type-system functions
 *
 **********************************************/


Type* Endian_initType(void)
{
  if (Endian_classType == NULL)
  {
    Type* baseType = Enum_initType();
    VTable* vtable = Endian_initVTable();
    Type* type = Type_new("Endian", baseType, vtable, sizeof(Endian), sizeof(EndianVTable));
    Type_registerMethodImplementation(type, "fromStr", Endian_fromStr_1, 1);
    Type_registerMethodImplementation(type, "fromStr", Endian_fromStr, 2);
    Type_registerFieldImplementation(type, "big", Endian_big, NULL);
    Type_registerFieldImplementation(type, "little", Endian_little, NULL);
    Type_registerFieldImplementation(type, "vals", Endian_vals, NULL);
    Endian_classType = type;
    Endian_initStatic();
  }
  return Endian_classType;
}


VTable* Endian_initVTable(void)
{
  if (Endian_classVTable == NULL)
  {
    VTable* vtable = memoryAlloc(sizeof(EndianVTable));
    memcpy(vtable, Enum_initVTable(), sizeof(EnumVTable));
    Endian_classVTable = vtable;
  }
  return Endian_classVTable;
}


void Endian_initStatic(void)
{
}
